require 'net/http'
require "socket"

class Netfunc
	def Netfunc::HTTP_GET(host, path, port=80)
#		printf("Netfunc::HTTP_GET: http://%s:%s%s\n", host, port, path)
		response = ""
		Net::HTTP.version_1_2
		Net::HTTP.start(host, port) {|http|
			response = http.get(path)
		}

		return (response)
	end

	def Netfunc::HTTP_POST(host, path, port=80, data="")
		printf("Netfunc::HTTP_POST: http://%s:%s%s\n", host, port, path)
		Net::HTTP.version_1_2
		http = Net::HTTP.new(host, port)
		response = http.post(path, data)

		return (response)
	end


	def Netfunc::TCP_send(host, port, data)
		sock = TCPSocket.open(host, port)
		ret = sock.write(data)
		sock.close

		return (ret)
	end

	def Netfunc::TCP_recv(host, port)
		s0 = TCPServer.open(port)
		sock = s0.accept
		while buf = sock.gets
			data = data + buf
		end
		sock.close
		s0.close
		
		return (data)
	end

end

